﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace XingZhe
{
        public class ThemeSetting
        {

                private static Dictionary<string, object> themeDict = new Dictionary<string, object>();

                public static ThemeSetting Current { get; private set; }

                static ThemeSetting()
                {
                        ThemeSetting.Current = new ThemeSetting();
                }

                public object this[string key]
                {
                        get
                        {
                                if (ThemeSetting.themeDict.ContainsKey(key))
                                {
                                        return ThemeSetting.themeDict[key];
                                }
                                else
                                {
                                        return null;
                                }
                        }

                        private set
                        {
                                if (ThemeSetting.themeDict.ContainsKey(key))
                                {
                                        ThemeSetting.themeDict[key] = value;
                                }
                                else
                                {
                                        ThemeSetting.themeDict.Add(key, value);
                                }
                        }
                }
                public static void LoadTheme(Uri themeUri)
                {
                        if (themeUri == null)
                        {
                                return;
                        }

                        ResourceDictionary dictionaries = new ResourceDictionary();

                        var themeStyles = new ResourceDictionary { Source = themeUri };
                        dictionaries.MergedDictionaries.Add(themeStyles);

                        ResourceDictionary appResources = App.Current.Resources;
                        foreach (DictionaryEntry entry in dictionaries.MergedDictionaries[0])
                        {
                                if (entry.Value != null && entry.Key.GetType() == typeof(string))
                                {
                                        ThemeSetting.Current[entry.Key.ToString()] = entry.Value;
                                }
                        }
                }
        }
}
